<?
    $this->head('css', 'assets/admin_categories');
?>

<h1>Kategorije</h1>

<p>
    <?= $this->link('+Nova kategorija', "/admin_categories/add/", array(
        'remote'=>true,
        'onclick'=>"location.hash='!'+$(this).data('url')",
        'data' => array(
            'before'   => 'categoryLoading()',
            'complete' => 'editCategory(req)'
        )
    )) ?>
</p>
<?= $this->element('category_tree', array('edit' => true)) ?>
<div class="category-main left">
</div>

<script type="text/javascript">
$(function(){
    locationHash(editCategory, function(url) {
        id = url.match(/\d+$/);
        if (id) {
            id = id[0];
            treeSelect(id);
        }
        return url;
    });
});
function editCategory(req) {
    throbberHide();
    var main = $('.category-main').removeClass('loading');

    if (req.status == 200) {
        main.html(req.responseText);
    } else {
        main.html(req.status+'. '+req.statusText);
    }
}
function categoryLoading() {
    $('.category-main').addClass('loading');
}
</script>